<?php
namespace Admin\Controller;
use Think\Controller;

use Alidayu\AlidayuClient as Client;
use Alidayu\Request\SmsNumSend;

class LoginController extends Controller {
    public function login(){
        $this->display();
    }
    public function do_login(){
        if(IS_POST){
            $username = I('username');
            $password = I('password');
            $user_object = D('Admin');
            $user_info = $user_object->login($username,$password);
            if(!$user_info){
                $this->error($user_object->getError());
            }

            // 设置登录状态
            $uid = $user_object->auto_login($user_info);
            if ($uid) {
                $this->success('恭喜您，登陆成功',U('Admin/Index/index'));
            } else {
                $this->logout();
            }
        }
    }
    public function logout()
    {
        session(null);
        $this->success('退出成功！', U('Login/login'));
    }
}